#! python

import pika, sys

credentials = pika.PlainCredentials('admin', 'admin')
conn_param = pika.ConnectionParameters('192.168.1.5', 5672, '/',  credentials = credentials)

conn_broker = pika.BlockingConnection(conn_param)

channel = conn_broker.channel()

channel.exchange_declare(exchange = "message", type = "topic", passive = False, durable = False, auto_delete = False)

channel.queue_declare(queue = "hello-queue")
channel.queue_bind(queue = "hello-queue", exchange = "message", routing_key = "example.text");

def msg_consumer(channel, method, header, body):
	channel.basic_ack(delivery_tag = method.delivery_tag)
	if body == "quit":
		channel.basic_cancel(consumer_tag = "hello-consumer")
		channel.stop_consuming()
	else :
		print body
	return

channel.basic_consume(msg_consumer, queue = "hello-queue", consumer_tag = "hello-consumer")
channel.start_consuming()